package cn.gong.movie.utils;

import java.util.Calendar;

import framework.utils.LogUtils;

public class DateUtils {
	private static String[] DAY_31 = new String[31];
	private static String[] DAY_30 = new String[30];
	private static String[] DAY_29 = new String[29];
	private static String[] DAY_28 = new String[28];
	private static String[] MONTH = new String[12];
	private static String[] YEAR_TOTAL = new String[200];

	static {
		for (int i = 0; i < 31; i++) {
			String day = (i + 1) + "";

			if (day.length() == 1) {
				day = "0" + day;
			}

			switch (i) {
			default:
				DAY_28[i] = day;
			case 28:
				DAY_29[i] = day;
			case 29:
				DAY_30[i] = day;
			case 30:
				DAY_31[i] = day;
				break;
			}
		}

		for (int i = 0; i < 12; i++) {
			String month = (i + 1) + "";
			if (month.length() == 1) {
				month = "0" + month;
			}

			MONTH[i] = month;
		}

		Calendar instance = Calendar.getInstance();
		int nowYear = instance.get(Calendar.YEAR);
		for (int i = 0; i < 200; i++) {
			YEAR_TOTAL[i] = (nowYear + i - 99) + "";
		}

	}

	public static String[] getYearArrayTotal() {
		return YEAR_TOTAL;
	}

	public static String[] getMonthArrayTotal() {
		return MONTH;
	}

	public static String[] getDayArrayTotal(String yearStr, int monthPosition) {
		switch (monthPosition + 1) {
		case 1:
		case 3:
		case 5:
		case 7:
		case 8:
		case 10:
		case 12:
			return DAY_31;
		case 2:
			int year = Integer.valueOf(yearStr.substring(0, yearStr.length() - 1));
			LogUtils.log("year:" + year);
			if (year % 4 == 0) {
				LogUtils.log("day_29");
				return DAY_29;
			} else {
				LogUtils.log("day_28");
				return DAY_28;
			}
		default:
			return DAY_30;
		}
	}
}
